<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='zhyyglhtxt'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
    <style>
        html {background:#fff;}
    </style>

</head>

<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">

    <form:form commandName="page" method="${_method }" class="layui-form">
        <input type="hidden" name="_method" value="${_method }"/>
        <form:hidden path="id"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><fmt:message key='ymmc'/></label>
            <div class="layui-input-block">
                <form:input path="name" class="layui-input" placeholder="<fmt:message key='cdmc'/>" style="width: 300px;"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><fmt:message key='xddz'/></label>
            <div class="layui-input-block">
                <form:input path="href" class="layui-input" placeholder="<fmt:message key='ymxddz'/>" style="width: 300px;"/>
            </div>
        </div>

        <div class="layui-form-item" style="margin-bottom: 10px;" id="params">
            <form:hidden path="permissionData" id="params-hidden"/>
            <label class="layui-form-label"><fmt:message key='qxld'/></label>
            <a href="javascript:void(0);" class="layui-btn layui-btn-mini" style="float: left;" id="addParams"><i class="layui-icon">&#xe654;</i></a>
            <label class="layui-form-label" style="width: auto"><fmt:message key='1-'/></label>
            <br><br><br>

            <c:forEach items="${page.permissions}" var="item">
                <div class='layui-block' style='margin-left: 60px; margin-bottom: 10px; line-height:  36px;' id='params-${item.id}'>
                    <label class='layui-form-label'><fmt:message key='qxm'/>:</label>
                    <input type='text' name='' value="${item.name}" autocomplete='off' class='layui-input paramsKey' data='${item.id}' style='width: 100px; display: inline-block; float: left;'>
                    <label class='layui-form-label'><fmt:message key='qxz1'/>:</label>
                    <input type='text' name='' value="${item.permission}" autocomplete='off' class='layui-input paramsValue-${item.id}' style='width: 100px; display: inline-block; float: left;'>
                    <a href='javascript:void(0);' class='layui-btn layui-btn-mini layui-btn-danger subject-params' data='params-${item.id}' style='margin-left: 10px;'><i class='layui-icon'>&#xe640;</i></a>
                </div>
            </c:forEach>

        </div>


        <div class="layui-input-block">
            <div style="display: none"><input type="button" value="<fmt:message key='bc'/>" class="layui-btn" id="submit"></div>
        </div>

    </form:form>

</div>

<script>

    $(function () {
        $("#submit").click(function () {
            var result = [];
            $(".paramsKey").each(function (index, item) {
                var id = $(this).attr("data");
                var key = $(item).val();

                var items = "";
                items += key + ":" + $(".paramsValue-" + id).val();


                result.push(items);
            });

            $("#params-hidden").attr("value", result.join(";"));


            $("form").ajaxSubmit({
                success: function (result) {
                    if (result.status) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.$("#search").click();
                    } else {
                        alert(result.message);
                    }
                }
            });

        });

        $("#addParams").click(function () {
            var id = Math.floor(Math.random() * 10000);
            $("#params").append("<div class='layui-block' style='margin-left: 60px; margin-bottom: 10px; line-height:  36px;' id='params-" + id + "'><label class='layui-form-label'><fmt:message key='qxm'/>:</label><input type='text' name='' autocomplete='off' class='layui-input paramsKey' data='" + id + "' style='width: 100px; display: inline-block; float: left;'><label class='layui-form-label'><fmt:message key='qxz1'/>:</label><input type='text' name='' autocomplete='off' class='layui-input paramsValue-" + id + "'  style='width: 100px; display: inline-block; float: left;'><a href='javascript:void(0);'  class='layui-btn layui-btn-mini layui-btn-danger subject-params' data='params-" + id + "' style='margin-left: 10px;'><i class='layui-icon'>&#xe640;</i></a></div>");
        });

        $(document).on("click", ".subject-params", function () {
            var id = $(this).attr("data");
            $("#" + id).remove();
        });


    });
</script>
</body>
</fmt:bundle>
</html>